package video;

import cn.hutool.json.JSONUtil;
import video.vo.PropertiesModel;
import video.vo.up.BiliInfoModel;
import video.vo.up.BiliRespVO;

import java.io.IOException;
import java.util.List;

/**
 * 下载 Up主主页 封面图片文件 和 生成下载的bat文件
 * @author 胡琦
 * @date 2022-04-15 星期五 22:18
 */
public class CreateBilibiliDownFileDemo {
    /** 封面图片存放的文件夹 */
    private final static String GRAPH_FOLDER = "\\img\\";

    /** 文件存放的位置 */
    private final static String FILE_PRE = "D:\\视频\\UP视频\\桃布";
    /** 需要解析的 json 字符串*/
    private final static String JSON = "{\"code\":0,\"message\":\"0\",\"ttl\":1,\"data\":{\"list\":{\"tlist\":{\"160\":{\"tid\":160,\"count\":1,\"name\":\"生活\"},\"3\":{\"tid\":3,\"count\":8,\"name\":\"音乐\"}},\"vlist\":[{\"comment\":44,\"typeid\":31,\"play\":761,\"pic\":\"http://i0.hdslb.com/bfs/archive/716784ca26a7b390b2d1aa3430a748a46ee94141.jpg\",\"subtitle\":\"\",\"description\":\"现在是凌晨四点，我睡不着觉，越来越精神了怎么办\",\"copyright\":\"1\",\"title\":\"up主凌晨emo，摆烂式更新\",\"review\":0,\"author\":\"桃布\",\"mid\":432367954,\"created\":1658261568,\"length\":\"02:15\",\"video_review\":3,\"aid\":428502615,\"bvid\":\"BV1tG411p7mq\",\"hide_click\":false,\"is_pay\":0,\"is_union_video\":0,\"is_steins_gate\":0,\"is_live_playback\":0},{\"comment\":34,\"typeid\":31,\"play\":1241,\"pic\":\"http://i2.hdslb.com/bfs/archive/62ce8d68ecf43b7b5f196e1c39f420ccc18908bd.jpg\",\"subtitle\":\"\",\"description\":\"-\",\"copyright\":\"1\",\"title\":\"[达尔文弹唱]“进化成更好的人”\",\"review\":0,\"author\":\"桃布\",\"mid\":432367954,\"created\":1657291577,\"length\":\"01:38\",\"video_review\":2,\"aid\":940731864,\"bvid\":\"BV1RW4y1U7QJ\",\"hide_click\":false,\"is_pay\":0,\"is_union_video\":0,\"is_steins_gate\":0,\"is_live_playback\":0},{\"comment\":62,\"typeid\":31,\"play\":2726,\"pic\":\"http://i1.hdslb.com/bfs/archive/d54294bb4640daeb37a11c59c2eea0952212dd82.jpg\",\"subtitle\":\"\",\"description\":\"-\",\"copyright\":\"1\",\"title\":\"[一点点喜欢弹唱]“我对你不止一点点喜欢”，和在头发里睡觉的小鹦鹉一起\",\"review\":0,\"author\":\"桃布\",\"mid\":432367954,\"created\":1656847565,\"length\":\"01:22\",\"video_review\":0,\"aid\":555609215,\"bvid\":\"BV1Bv4y1T7jZ\",\"hide_click\":false,\"is_pay\":0,\"is_union_video\":0,\"is_steins_gate\":0,\"is_live_playback\":0},{\"comment\":77,\"typeid\":31,\"play\":11845,\"pic\":\"http://i1.hdslb.com/bfs/archive/d4992713d9f78cf7521157006b8af5ffd2a04030.jpg\",\"subtitle\":\"\",\"description\":\"-\",\"copyright\":\"1\",\"title\":\"[年轮翻唱]    “回忆苦涩的吻痕是树根”\",\"review\":0,\"author\":\"桃布\",\"mid\":432367954,\"created\":1656512727,\"length\":\"01:31\",\"video_review\":5,\"aid\":470477239,\"bvid\":\"BV1rT41137jP\",\"hide_click\":false,\"is_pay\":0,\"is_union_video\":0,\"is_steins_gate\":0,\"is_live_playback\":0},{\"comment\":69,\"typeid\":31,\"play\":4276,\"pic\":\"http://i1.hdslb.com/bfs/archive/9da71436d545b6306d4955ee5809fc11594cf785.jpg\",\"subtitle\":\"\",\"description\":\"-\",\"copyright\":\"1\",\"title\":\"这首歌你就随便听听，女大学生宿舍弹唱\",\"review\":0,\"author\":\"桃布\",\"mid\":432367954,\"created\":1653959901,\"length\":\"01:27\",\"video_review\":10,\"aid\":684581933,\"bvid\":\"BV1zU4y1y7eb\",\"hide_click\":false,\"is_pay\":0,\"is_union_video\":0,\"is_steins_gate\":0,\"is_live_playback\":0},{\"comment\":6,\"typeid\":31,\"play\":454,\"pic\":\"http://i2.hdslb.com/bfs/archive/6d32aeacc4dceb168bc50cbf659b68c65e14e3bb.jpg\",\"subtitle\":\"\",\"description\":\"-\",\"copyright\":\"1\",\"title\":\"尚好的青春都是你……\",\"review\":0,\"author\":\"桃布\",\"mid\":432367954,\"created\":1652094162,\"length\":\"01:43\",\"video_review\":0,\"aid\":638928956,\"bvid\":\"BV1MY4y1r7F6\",\"hide_click\":false,\"is_pay\":0,\"is_union_video\":0,\"is_steins_gate\":0,\"is_live_playback\":0},{\"comment\":18,\"typeid\":31,\"play\":1140,\"pic\":\"http://i0.hdslb.com/bfs/archive/068507d08178b52a0a51dc979d66e77dbcb81763.png\",\"subtitle\":\"\",\"description\":\"-\",\"copyright\":\"1\",\"title\":\"吉他弹唱new boy~\",\"review\":0,\"author\":\"桃布\",\"mid\":432367954,\"created\":1647356617,\"length\":\"04:03\",\"video_review\":3,\"aid\":382285507,\"bvid\":\"BV1QZ4y1z7qs\",\"hide_click\":false,\"is_pay\":0,\"is_union_video\":0,\"is_steins_gate\":0,\"is_live_playback\":0},{\"comment\":31,\"typeid\":31,\"play\":1904,\"pic\":\"http://i1.hdslb.com/bfs/archive/0abdf7da092c25f63db1b1f8d34f587a0d2dad83.jpg\",\"subtitle\":\"\",\"description\":\"-\",\"copyright\":\"1\",\"title\":\"女大学生宿舍唱海芋恋\",\"review\":0,\"author\":\"桃布\",\"mid\":432367954,\"created\":1642227627,\"length\":\"01:25\",\"video_review\":6,\"aid\":850650913,\"bvid\":\"BV11L4y1b74d\",\"hide_click\":false,\"is_pay\":0,\"is_union_video\":0,\"is_steins_gate\":0,\"is_live_playback\":0},{\"comment\":76,\"typeid\":21,\"play\":26986,\"pic\":\"http://i1.hdslb.com/bfs/archive/67ff1299df5e020616b4d09cd4b9801ba7caab4a.jpg\",\"subtitle\":\"\",\"description\":\"-\",\"copyright\":\"1\",\"title\":\"小公鸡做窝\",\"review\":0,\"author\":\"桃布\",\"mid\":432367954,\"created\":1631033639,\"length\":\"01:27\",\"video_review\":17,\"aid\":377790385,\"bvid\":\"BV1bf4y1A7rw\",\"hide_click\":false,\"is_pay\":0,\"is_union_video\":0,\"is_steins_gate\":0,\"is_live_playback\":0}]},\"page\":{\"pn\":1,\"ps\":30,\"count\":9},\"episodic_button\":{\"text\":\"播放全部\",\"uri\":\"//www.bilibili.com/medialist/play/432367954?from=space\"}}}";





    public static void main(String[] args) throws IOException {
        PropertiesModel properties = PropertiesModel.builder().filePre(FILE_PRE).json(JSON).build();
        // 解析json
        BiliRespVO bModelList = JSONUtil.toBean(properties.getJson(), BiliRespVO.class);
        // 解析异常就会空指针, 懒得做异常处理了
        List<BiliInfoModel> vlist = bModelList.getData().getList().getVlist();
        DownloadPictureTest.createBatFile(vlist, properties);
        // 下载所有封面图片
        DownloadPictureTest.downImages(vlist, properties.getFilePre() + GRAPH_FOLDER);
        System.out.println("!!!!   SUCCESS   !!!!!");
    }
}
